package cn.ctyun.ipush.controller;

import cn.ctyun.ipush.constant.ResultInfo;
import cn.ctyun.ipush.dao.SaleDao;
import cn.ctyun.ipush.dto.ResultDto;
import cn.ctyun.ipush.model.EmailModel;
import cn.ctyun.ipush.model.HbbtProductModel;
import cn.ctyun.ipush.model.HbbtSalesHisModel;
import cn.ctyun.ipush.service.EmailService;
import cn.ctyun.ipush.service.ProdService;
import cn.ctyun.ipush.service.SaleService;
import cn.ctyun.ipush.utils.ConfigUtils;
import cn.ctyun.ipush.utils.DataUtils;
import cn.ctyun.ipush.utils.DateUtils;
import cn.ctyun.ipush.utils.EmailUtils;
import cn.ctyun.ipush.web.user.bo.UserModel;
import cn.ctyun.ipush.web.user.constanst.SessionAttributeKeys;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.dexcoder.commons.utils.UUIDUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * User: user
 * Date: 16-7-4
 * Time: 上午10:41
 * To change this template use File | Settings | File Templates.
 */
@Controller
public class SaleController {

    @Autowired
    private SaleService saleService;

    @Autowired
    private ProdService prodService;

    /* 日志对象 */
    private final Logger LOG = LoggerFactory.getLogger(SaleController.class);

    @RequestMapping(value = "saleIntoPage", method = RequestMethod.GET)
    public ModelAndView intoPage(HttpSession session, HttpServletRequest request) {
        /**
         * productInputMsg 需要返回当前用户的信息
         */
        try {
            UserModel o = (UserModel) session.getAttribute("userInfo");
            if (o != null) {
                String sql = String.format("select a.*,b.prod_name,b.prod_type from  hbbt_sales_his_model a inner join hbbt_product_model b on a.prod_id=b.hbbt_product_model_id where a.is_deleted='0' and a.create_userid='%s' and a.create_date like '%%%s%%'", o.getUserModelId(),DateUtils.dateToString(new Date()).substring(0,10));
                List list = saleService.queryListBySql(ConfigUtils.getStringValue("jdbcUrl"), ConfigUtils.getStringValue("username"), ConfigUtils.getStringValue("password"), sql);
                Map<String, Object> data = new HashMap<String, Object>();
                data.put("hbbtSalesHisModelList", list);
                return new ModelAndView("IB_DY_IINPUTBONUS", data);
            } else {
                return new ModelAndView("IB_DY_IINPUTBONUS", null);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return new ModelAndView("IB_DY_IINPUTBONUS", null);
        }
    }

    @RequestMapping(value = "save", method = RequestMethod.POST)
    public ModelAndView save(HttpServletRequest request, HttpSession session) {
        String prod_type = request.getParameter("productType");
        String prod_name = request.getParameter("productId");
        String sale_nums = request.getParameter("productNumber");
        String cust_name = request.getParameter("customerName");
        String cust_tele = request.getParameter("customerTele");
        UserModel o = (UserModel) session.getAttribute("userInfo");
        try {
            HbbtSalesHisModel hbbtSalesHisModel = new HbbtSalesHisModel();
            hbbtSalesHisModel.setHbbtSalesHisModelId(UUIDUtils.getUUID32());
            hbbtSalesHisModel.setCustName(cust_name);
            hbbtSalesHisModel.setCustMobile(cust_tele);
            hbbtSalesHisModel.setSaleNums(sale_nums);

            HbbtProductModel hbbtProductModel = new HbbtProductModel();
            hbbtProductModel.setProdType(prod_type);
            hbbtProductModel.setProdName(prod_name);
            hbbtProductModel.setIsDeleted("0");
            List<HbbtProductModel> hbbtProductModelList = prodService.queryList(hbbtProductModel);


            hbbtSalesHisModel.setProdId(hbbtProductModelList.get(0).getHbbtProductModelId());
            hbbtSalesHisModel.setCreateUserid(o.getUserModelId());
            hbbtSalesHisModel.setCreateDate(DateUtils.dateToString(new Date()));
            hbbtSalesHisModel.setIsDeleted("0");
            hbbtSalesHisModel.setProdRewardNow(String.valueOf(Integer.parseInt(hbbtProductModelList.get(0).getProdReward()) * Integer.parseInt(sale_nums)));
            saleService.save(hbbtSalesHisModel);

            String sql = String.format("select a.*,b.prod_name,b.prod_type from  hbbt_sales_his_model a inner join hbbt_product_model b on a.prod_id=b.hbbt_product_model_id where a.is_deleted='0' and a.create_userid='%s' and a.create_date like '%%%s%%' ", o.getUserModelId(),DateUtils.dateToString(new Date()).substring(0,10));
            List list = saleService.queryListBySql(ConfigUtils.getStringValue("jdbcUrl"), ConfigUtils.getStringValue("username"), ConfigUtils.getStringValue("password"), sql);
            Map<String, Object> data = new HashMap<String, Object>();
            data.put("hbbtSalesHisModelList", list);
            return new ModelAndView("IB_DY_IINPUTBONUS", data);

        } catch (Exception ex) {
              return new ModelAndView("IB_DY_IINPUTBONUS", null);
        }
    }

    @RequestMapping(value = "query", method = RequestMethod.GET)
    @ResponseBody
    public ResultDto query(HttpServletRequest request) {
        ResultDto resultDto = new ResultDto();
        String id = request.getParameter("id");
        try {
            String sql = String.format("select *  from  hbbt_sales_his_model where hbbt_sales_his_model_id = '%s'", id);
            List list = saleService.queryListBySql(ConfigUtils.getStringValue("jdbcUrl"), ConfigUtils.getStringValue("username"), ConfigUtils.getStringValue("password"), sql);
            return resultDto.setStatus(ResultInfo.success).setInfo(list);
        } catch (Exception ex) {
            LOG.info("失败：" + ex.getMessage());
            return resultDto.setStatus(ResultInfo.failure).setInfo("失败");
        }
    }

    @RequestMapping(value = "delete", method = RequestMethod.GET)
    public ModelAndView delete(HttpServletRequest request, HttpSession session) {
        ResultDto resultDto = new ResultDto();
        String id = request.getParameter("id");
        UserModel o = (UserModel) session.getAttribute("userInfo");
        try {
            saleService.delete(id);
            String sql = String.format("select a.*,b.prod_name,b.prod_type from  hbbt_sales_his_model a inner join hbbt_product_model b on a.prod_id=b.hbbt_product_model_id where a.is_deleted='0' and a.create_userid='%s' and  a.create_date like '%%%s%%'", o.getUserModelId(),DateUtils.dateToString(new Date()).substring(0,10));
            List list = saleService.queryListBySql(ConfigUtils.getStringValue("jdbcUrl"), ConfigUtils.getStringValue("username"), ConfigUtils.getStringValue("password"), sql);
            Map<String, Object> data = new HashMap<String, Object>();
            data.put("hbbtSalesHisModelList", list);
            return new ModelAndView("IB_DY_IINPUTBONUS", data);
        } catch (Exception ex) {
          return new ModelAndView("IB_DY_IINPUTBONUS", null);
        }
    }


    @RequestMapping(value = "getThreeDayBonusByUserid", method = RequestMethod.POST)
    @ResponseBody
    public ResultDto getThreeDayBonusByUserid(HttpServletRequest request) {
        ResultDto resultDto = new ResultDto();
        String requestJsonParam = DataUtils.getJsonFromRequest(request);
        JSONObject jsonObject = JSON.parseObject(requestJsonParam);
        UserModel systemUserModel = (UserModel) request.getSession().getAttribute(SessionAttributeKeys.SESSION_ATTR_KEY_USERINFO);

        try {
            String sql = String.format("SELECT left(create_date,10) 'create_date',sum(ifnull(prod_reward_now,0)) 'bonus' FROM hbbt_sales_his_model where is_deleted='0' and create_userid='%s' and left(create_date,10) in ('%s','%s','%s') group by left(create_date,10)  ", systemUserModel.getUserModelId(), (String) jsonObject.get("lastThird"), (String) jsonObject.get("lastSecond"), (String) jsonObject.get("lastFirst"));
            List list = saleService.queryListBySql(ConfigUtils.getStringValue("jdbcUrl"), ConfigUtils.getStringValue("username"), ConfigUtils.getStringValue("password"), sql);
            Map rowData = new HashMap();
            if (list.size() == 0) {
                rowData.put("bonus", 0);
                rowData.put("create_date", 0);
                list.add(rowData);
                rowData.put("bonus", 0);
                rowData.put("create_date", 0);
                list.add(rowData);
                rowData.put("bonus", 0);
                rowData.put("create_date", 0);
                list.add(rowData);
            } else if (list.size() == 1) {
                rowData.put("bonus", 0);
                rowData.put("create_date", 0);
                list.add(rowData);
                rowData.put("bonus", 0);
                rowData.put("create_date", 0);
                list.add(rowData);
            } else if (list.size() == 2) {
                rowData.put("bonus", 0);
                rowData.put("create_date", 0);
                list.add(rowData);
            }
            String startDate = DateUtils.getWeekStartDate();
            String endDate = DateUtils.getWeekLastDay(startDate);
            String sql1 = String.format("SELECT sum(sale_nums) 'count',sum(ifnull(prod_reward_now,0)) 'bonus' FROM hbbt_sales_his_model where is_deleted='0'and create_userid='%s' and create_date >= '%s' and create_date <='%s'", systemUserModel.getUserModelId(), startDate, endDate);
            List list1 = saleService.queryListBySql(ConfigUtils.getStringValue("jdbcUrl"), ConfigUtils.getStringValue("username"), ConfigUtils.getStringValue("password"), sql1);
            if (((HashMap) list1.get(0)).get("count").equals(new Long(0))) {
                list1.clear();
                Map rowData1 = new HashMap();
                rowData1.put("bonus", 0);
                rowData1.put("count", 0);
                list1.add(rowData1);
            }
            list.add(list1);
            String monthdate = startDate.substring(0, 7);
            String sql2 = String.format("SELECT sum(ifnull(prod_reward_now,0)) 'bonus' FROM hbbt_sales_his_model where is_deleted='0' and create_userid='%s'  and create_date like '%%%s%%'", systemUserModel.getUserModelId(), monthdate);
            List list2 = saleService.queryListBySql(ConfigUtils.getStringValue("jdbcUrl"), ConfigUtils.getStringValue("username"), ConfigUtils.getStringValue("password"), sql2);

            list.add(list2);
            if (((HashMap) list2.get(0)).get("bonus") == null) {
                list2.clear();
                Map rowData2 = new HashMap();
                rowData2.put("bonus", 0);
                list2.add(rowData2);
            }
            return resultDto.setStatus(ResultInfo.success).setInfo(list);
        } catch (Exception ex) {
            LOG.info("失败：" + ex.getMessage());
            return resultDto.setStatus(ResultInfo.failure).setInfo("失败");
        }
    }

    //getThreeDayBonusByDz
    @RequestMapping(value = "getThreeDayBonusByDz", method = RequestMethod.POST)
    @ResponseBody
    public ResultDto getThreeDayBonusByDz(HttpServletRequest request) {
        ResultDto resultDto = new ResultDto();
        String requestJsonParam = DataUtils.getJsonFromRequest(request);
        JSONObject jsonObject = JSON.parseObject(requestJsonParam);
        UserModel systemUserModel = (UserModel) request.getSession().getAttribute(SessionAttributeKeys.SESSION_ATTR_KEY_USERINFO);

        try {
            String sql = String.format("SELECT left(create_date,10) 'create_date',sum(ifnull(prod_reward_now,0)) 'bonus' FROM hbbt_sales_his_model a inner join user_model b on a.create_userid=b.user_model_id where is_deleted='0' and b.location='%s' and left(a.create_date,11) in ('%s','%s','%s') group by left(create_date,10)  ", systemUserModel.getLocation(), (String) jsonObject.get("lastThird"), (String) jsonObject.get("lastSecond"), (String) jsonObject.get("lastFirst"));
            List list = saleService.queryListBySql(ConfigUtils.getStringValue("jdbcUrl"), ConfigUtils.getStringValue("username"), ConfigUtils.getStringValue("password"), sql);
            Map rowData = new HashMap();
            if (list.size() == 0) {
                rowData.put("bonus", 0);
                rowData.put("create_date", 0);
                list.add(rowData);
                rowData.put("bonus", 0);
                rowData.put("create_date", 0);
                list.add(rowData);
                rowData.put("bonus", 0);
                rowData.put("create_date", 0);
                list.add(rowData);
            } else if (list.size() == 1) {
                rowData.put("bonus", 0);
                rowData.put("create_date", 0);
                list.add(rowData);
                rowData.put("bonus", 0);
                rowData.put("create_date", 0);
                list.add(rowData);
            } else if (list.size() == 2) {
                rowData.put("bonus", 0);
                rowData.put("create_date", 0);
                list.add(rowData);
            }
            String startDate = DateUtils.getWeekStartDate();
            String endDate = DateUtils.getWeekLastDay(startDate);
            String sql1 = String.format("SELECT sum(sale_nums) 'count',sum(ifnull(prod_reward_now,0)) 'bonus' FROM hbbt_sales_his_model a inner join user_model b on a.create_userid=b.user_model_id where a.is_deleted='0'and b.location='%s' and left(a.create_date,11) >= '%s' and left(a.create_date,11) <='%s'", systemUserModel.getLocation(), startDate, endDate);
            List list1 = saleService.queryListBySql(ConfigUtils.getStringValue("jdbcUrl"), ConfigUtils.getStringValue("username"), ConfigUtils.getStringValue("password"), sql1);
            if (((HashMap) list1.get(0)).get("count").equals(new Long(0))) {
                list1.clear();
                Map rowData1 = new HashMap();
                rowData1.put("bonus", 0);
                rowData1.put("count", 0);
                list1.add(rowData1);
            }
            list.add(list1);
            String monthdate = startDate.substring(0, 7);
            String sql2 = String.format("SELECT sum(ifnull(prod_reward_now,0)) 'bonus' FROM hbbt_sales_his_model a inner join user_model b on a.create_userid=b.user_model_id where is_deleted='0' and b.location='%s'  and left(create_date,8) like '%%%s%%'", systemUserModel.getLocation(), monthdate);
            List list2 = saleService.queryListBySql(ConfigUtils.getStringValue("jdbcUrl"), ConfigUtils.getStringValue("username"), ConfigUtils.getStringValue("password"), sql2);

            list.add(list2);
            if (((HashMap) list2.get(0)).get("bonus") == null) {
                list2.clear();
                Map rowData2 = new HashMap();
                rowData2.put("bonus", 0);
                list2.add(rowData2);
            }
            return resultDto.setStatus(ResultInfo.success).setInfo(list);
        } catch (Exception ex) {
            LOG.info("失败：" + ex.getMessage());
            return resultDto.setStatus(ResultInfo.failure).setInfo("失败");
        }
    }


    ///店员查询自己
    @RequestMapping(value = "dySearch", method = RequestMethod.POST)
    public ModelAndView dySearch(HttpSession session, HttpServletRequest request) {
        /**
         * bonusIntoPage 需要返回当前用户的信息
         */
        String bonusBeginTime = request.getParameter("bonusBeginTime");
        String bonusEndTime = request.getParameter("bonusEndTime");
        String productType = request.getParameter("productType");
        String productId = request.getParameter("productId");
        UserModel o = (UserModel) session.getAttribute("userInfo");
        try {
            if (o != null) {
//                String sql = String.format("select a.*,b.prod_name,b.prod_type from  hbbt_sales_his_model a inner join hbbt_product_model b " +
//                        "on a.prod_id=b.hbbt_product_model_id where a.is_deleted='0' " +
//                        "and a.create_userid='%s' and a.create_date >= '%s' and a.create_date <= '%s' and b.prod_type='%s' and b.prod_name='%s' ", o.getUserModelId(), bonusBeginTime, bonusEndTime, productType, productId);
               String baseSql=String.format("select a.*,b.prod_name,b.prod_type from  hbbt_sales_his_model a inner join hbbt_product_model b on a.prod_id=b.hbbt_product_model_id where a.is_deleted='0' and  a.create_userid='%s'  ",o.getUserModelId());
                if(bonusBeginTime!=null && !bonusBeginTime.equals("")){
                    baseSql += String.format(" and a.create_date >= '%s'  ",bonusBeginTime);
                }

                if(bonusEndTime!=null && !bonusEndTime.equals("")){
                    baseSql += String.format(" and a.create_date <= '%s'  ",bonusBeginTime);
                }

                if(productType!=null && !productType.equals("")){
                    baseSql += String.format(" and b.prod_type='%s'  ",productType);
                }

                if(productId!=null && !productId.equals("")){
                    baseSql += String.format(" and b.prod_name='%s'  ",productId);
                }

                List list = saleService.queryListBySql(ConfigUtils.getStringValue("jdbcUrl"), ConfigUtils.getStringValue("username"), ConfigUtils.getStringValue("password"), baseSql);
                Map<String, Object> data = new HashMap<String, Object>();
                data.put("hbbtSalesHisModelList", list);
                return new ModelAndView("IB_DY_SEARCHBONUS", data);
            } else {
                return new ModelAndView("IB_DY_SEARCHBONUS", null);
            }
        } catch (Exception e) {
            return new ModelAndView("IB_DY_SEARCHBONUS", null);
        }
    }

    ///店长查询初始页面
    @RequestMapping(value = "dzSearchInfoPage", method = RequestMethod.GET)
    public ModelAndView dzSearchInfoPage(HttpSession session, HttpServletRequest request) {
        /**
         * bonusIntoPage 需要返回当前用户的信息
         */
        UserModel o = (UserModel) session.getAttribute("userInfo");
        try {
            if (o != null) {
                String sql = String.format("select a.*,b.prod_name,b.prod_type,c.user_realname from  hbbt_sales_his_model a inner join hbbt_product_model b on a.prod_id=b.hbbt_product_model_id inner join user_model c on a.create_userid=c.user_model_id where a.is_deleted='0' and c.location='%s'  ", o.getLocation());
                List list = saleService.queryListBySql(ConfigUtils.getStringValue("jdbcUrl"), ConfigUtils.getStringValue("username"), ConfigUtils.getStringValue("password"), sql);
                Map<String, Object> data = new HashMap<String, Object>();
                data.put("hbbtSalesHisModelList", list);
                return new ModelAndView("IB_DZ_SEARCHBONUS", data);
            } else {
                return new ModelAndView("IB_DZ_SEARCHBONUS", null);
            }
        } catch (Exception e) {
            return new ModelAndView("IB_DZ_SEARCHBONUS", null);
        }
    }

    ///店长查询
    @RequestMapping(value = "dzsearch", method = RequestMethod.POST)
    public ModelAndView dzsearch(HttpSession session, HttpServletRequest request) {
        /**
         * bonusIntoPage 需要返回当前用户的信息
         */
        String bonusBeginTime = request.getParameter("bonusBeginTime");
        String bonusEndTime = request.getParameter("bonusEndTime");
        String productType = request.getParameter("productType");
        String productId = request.getParameter("productId");

        UserModel o = (UserModel) session.getAttribute("userInfo");

        try {
            if (o != null) {
//                String sql = String.format("select a.*,b.prod_name,b.prod_type,c.user_realname from  hbbt_sales_his_model a inner " +
//                        "join hbbt_product_model b on a.prod_id=b.hbbt_product_model_id inner join user_model c " +
//                        "on a.create_userid=c.user_model_id  where a.is_deleted='0' " +
//                        "and a.create_date >= '%s' and a.create_date <= '%s' and b.prod_type='%s' and b.prod_name='%s'  and c.location='%s'",  bonusBeginTime, bonusEndTime, productType, productId,o.getLocation());
                String baseSql=String.format("select a.*,b.prod_name,b.prod_type,c.user_realname from  hbbt_sales_his_model a inner " +
                        "join hbbt_product_model b on a.prod_id=b.hbbt_product_model_id inner join user_model c " +
                        "on a.create_userid=c.user_model_id  where a.is_deleted='0' and   c.location='%s' ",o.getLocation());
                if(bonusBeginTime!=null && !bonusBeginTime.equals("")){
                    baseSql += String.format(" and a.create_date >= '%s' ",bonusBeginTime);
                }

                if(bonusEndTime!=null && !bonusEndTime.equals("")){
                    baseSql += String.format(" and a.create_date <= '%s' ",bonusEndTime);
                }

                if(productType!=null && !productType.equals("")){
                    baseSql += String.format(" and b.prod_type = '%s' ",productType);
                }

                if(productId!=null && !productId.equals("")){
                    baseSql += String.format("  and b.prod_name='%s' ",productId);
                }

                List list = saleService.queryListBySql(ConfigUtils.getStringValue("jdbcUrl"), ConfigUtils.getStringValue("username"), ConfigUtils.getStringValue("password"), baseSql);
                Map<String, Object> data = new HashMap<String, Object>();
                data.put("hbbtSalesHisModelList", list);
                return new ModelAndView("IB_DZ_SEARCHBONUS", data);
            } else {
                return new ModelAndView("IB_DZ_SEARCHBONUS", null);
            }
        } catch (Exception e) {
            return new ModelAndView("IB_DZ_SEARCHBONUS", null);
        }
    }


    //店内员工业绩排名dzRankInfoPage
    @RequestMapping(value = "dzRankInfoPage", method = RequestMethod.GET)
    public ModelAndView dzRankInfoPage(HttpSession session, HttpServletRequest request) {
        /**
         * productInputMsg 需要返回当前用户的信息
         */
        try {
            UserModel o = (UserModel) session.getAttribute("userInfo");
            if (o != null) {
                String sql = String.format("select c.user_realname as 'username',sum(sale_nums) as 'nums',sum(a.prod_reward_now)  as 'rewards' \n" +
                        "from  hbbt_sales_his_model a inner join hbbt_product_model b on a.prod_id=b.hbbt_product_model_id inner join \n" +
                        "user_model c on a.create_userid=c.user_model_id \n" +
                        "where a.is_deleted='0' and c.location='昆仑厅' \n" +
                        "group by c.user_realname", o.getLocation());
                List list = saleService.queryListBySql(ConfigUtils.getStringValue("jdbcUrl"), ConfigUtils.getStringValue("username"), ConfigUtils.getStringValue("password"), sql);
                Map<String, Object> data = new HashMap<String, Object>();
                data.put("hbbtSalesHisModelList", list);
                return new ModelAndView("IB_DZ_RANKBONUS", data);
            } else {
                return new ModelAndView("IB_DZ_RANKBONUS", null);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return new ModelAndView("IB_DZ_RANKBONUS", null);
        }
    }


    //dzranksearch店员销售业绩排名
    @RequestMapping(value = "dzranksearch", method = RequestMethod.POST)
    public ModelAndView dzranksearch(HttpSession session, HttpServletRequest request) {
        /**
         * productInputMsg 需要返回当前用户的信息
         */
        String bonusBeginTime = request.getParameter("bonusBeginTime");
        String bonusEndTime = request.getParameter("bonusEndTime");
        try {
            UserModel o = (UserModel) session.getAttribute("userInfo");
            if (o != null) {
//                String sql = String.format("select c.user_realname as 'username',sum(sale_nums) as 'nums',sum(a.prod_reward_now)  as 'rewards' " +
//                        "from  hbbt_sales_his_model a inner join hbbt_product_model b on a.prod_id=b.hbbt_product_model_id inner join " +
//                        "user_model c on a.create_userid=c.user_model_id " +
//                        "where a.is_deleted='0' and c.location='%s' " +
//                        "group by c.user_realname", o.getLocation());
                String baseSql=String.format("select c.user_realname as 'username',sum(sale_nums) as 'nums',sum(a.prod_reward_now)  as 'rewards' " +
                        "from  hbbt_sales_his_model a inner join hbbt_product_model b on a.prod_id=b.hbbt_product_model_id inner join " +
                        "user_model c on a.create_userid=c.user_model_id " +
                        "where a.is_deleted='0' and c.location='%s' ",o.getLocation());
                if(bonusBeginTime !=null && !bonusBeginTime.equals("")){
                    baseSql += String.format(" and a.create_date >= '%s' ",bonusBeginTime);
                }
                if(bonusEndTime !=null && !bonusEndTime.equals("")){
                    baseSql += String.format(" and a.create_date <= '%s' ",bonusEndTime);
                }
                baseSql += " group by c.user_realname";
                List list = saleService.queryListBySql(ConfigUtils.getStringValue("jdbcUrl"), ConfigUtils.getStringValue("username"), ConfigUtils.getStringValue("password"), baseSql);
                Map<String, Object> data = new HashMap<String, Object>();
                data.put("hbbtSalesHisModelList", list);
                return new ModelAndView("IB_DZ_RANKBONUS", data);
            } else {
                return new ModelAndView("IB_DZ_RANKBONUS", null);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return new ModelAndView("IB_DZ_RANKBONUS", null);
        }
    }
}
